﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using Microhard.Core.DBUtility;

namespace Microhard.Permission.MVCFilter
{

    [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = true)]
    public class MVCFilterAtrForReDirect : ActionFilterAttribute
    {
        public string RedirectActionName { set; get; }
        public string RedirectControllerName { set; get; }
        public string RedirectAreaName { set; get; }
        public string ResultModelExchangeParmsModelKeys { set; get; }
        public Type RedirectParmModelType { set; get; }
        public string Condition { set; get; }

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var rm = new RedirectModel();
            rm.Condition = this.Condition;
            rm.RedirectActionName = this.RedirectActionName;
            rm.RedirectAreaName = this.RedirectAreaName;
            rm.RedirectControllerName = this.RedirectControllerName;
            rm.RedirectParmModelType = this.RedirectParmModelType;
            rm.ResultModelExchangeParmsModelKeys = this.ResultModelExchangeParmsModelKeys;
            var scope = filterContext.ActionParameters["scope"] as ScopeResult;
            scope.AfterActionExecuted = rm;

            filterContext.ActionParameters["scope"] = scope;
        }

    }
}
